require "ImguiWin/BaseImguiWindow"
require "Common/GUIFun"

local P = NewClass(BaseImguiWindow, ClassFromFile(...));

local GUILayout = UnityEngine.GUILayout
local GUI = UnityEngine.GUI
local Screen = UnityEngine.Screen
local dontDestroyObjs = nil

local addSpace = 50

local exeText = ""

function P:Init(params)

end


function P:Cmd(msg, donClose)
	KBEngineLua.player():sendChatMessage(msg)
	if not donClose then
		self._funObj:Close()
	end
end

function P:Show()
	local space = 0
	GUILayout.BeginArea(self:GetFullScreenAreaRect())
	GUILayout.BeginVertical()



	self.guiInfo.scrollPos = GUILayout.BeginScrollView(self.guiInfo.scrollPos, false, true, GUILayout.Width(Screen.width));
	GUILayout.BeginVertical()
	





	exeText = GUIFun.TextArea(exeText, "exe text: ", false, space)
	-- if GUIFun.Button("execute", false, 0) then
	-- 	loadstring(exeText)();
	-- end

	-- if GUIFun.Button("clear", false, 0) then
	-- 	exeText = ""
	-- end








	GUILayout.BeginHorizontal()
	GUILayout.EndHorizontal()


	GUILayout.EndVertical()
	GUILayout.EndScrollView();

	

	GUILayout.BeginHorizontal()

	if GUILayout.Button("close", GUIFun.Height(100)) then
		self._funObj:Close()
	end
	if GUILayout.Button("execute", GUIFun.Height(100)) then
		loadstring(exeText)();
	end
	if GUILayout.Button("clear", GUIFun.Height(100)) then
		exeText = ""
	end

	GUILayout.EndHorizontal()
	

	GUILayout.EndVertical()
	GUILayout.EndArea()
end

function P:OnGUI()
	GUIFun.Init()
	GUILayout.Box("", GUILayout.Height(Screen.height), GUILayout.Width(Screen.width))
	self:Show()

	local scrollPosition = self.guiInfo.scrollPos
	local scrollDragSpeed = self.guiInfo.scrollDragSpeed

	ImguiWindowCtrl.ScrollByTouch(scrollPosition, scrollDragSpeed)
end

-- function P:Update()
	
-- end